package com.gxa.customer.controller;

import com.gxa.common.commons.JsonResult;
import com.gxa.common.commons.R;
import com.gxa.common.pojo.ClientInfo;
import com.gxa.common.utils.EasyExcelUtils;
import com.gxa.customer.service.ClientListBaseInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping("/customer")
public class ClientListBaseInformationController {

    @Autowired
    private ClientListBaseInformationService clientListBaseInformationService;
    //分页查询所有客户基本信息
    @RequestMapping("/findAllClientBaseInformation")
    public JsonResult findAllClientBaseInformation(Integer currentPage,Integer pageSize){
        return clientListBaseInformationService.findAllClientBaseInformation(currentPage,pageSize);
    }
    //根据客户id查询客户基本信息
    @RequestMapping("/findClientBaseInformationById")
    public R findClientBaseInformationById(Long clientInfoId ){
        return clientListBaseInformationService.findClientBaseInformationById(clientInfoId);
    }
    //新建客户基本信息
    @PostMapping("/addClientBaseInformation")
    public R addClientBaseInformation(@RequestBody ClientInfo clientInfo){
        return clientListBaseInformationService.addClientBaseInformation(clientInfo);

    }
    //编辑客户基本信息（客户编号自动回显）
    @PostMapping("/updateClientBaseInformation")
    public R updateClientBaseInformation(@RequestBody ClientInfo clientInfo){
        return clientListBaseInformationService.updateClientBaseInformation(clientInfo);
    }
    //删除客户信息
    @RequestMapping("/deleteClientBaseInformation")
    public R deleteClientBaseInformation(Long clientInfoId){
        return clientListBaseInformationService.deleteClientBaseInformation(clientInfoId);
    }
    //根据关键字（编号/名称/拼音/护照号）分页搜索客户信息
    @RequestMapping("/findClientBaseInformationByKeyWordPage")
    public JsonResult findClientBaseInformationByKeyWordPage(Integer currentPage,Integer pageSize,String keyWord){
        return clientListBaseInformationService.findClientBaseInformationByKeyWordPage(currentPage,pageSize,keyWord);
    }
    //查询所有国家
    @RequestMapping("/findAllCountry")
    public R findAllCountry(){
        return clientListBaseInformationService.findAllCountry();
    }
    //客户名下添加国家（复选框）
    @PostMapping("/addCountryToClient")
    public R addCountryToClient(@RequestBody Map<String,Object> map){
        return clientListBaseInformationService.addCountryToClient(map);
    }
    //导出客户信息表
    @RequestMapping("/exportClientInfoToExcel")
    public R exportClientInfoToExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return clientListBaseInformationService.findAllclientToExcel(request,response);
    }
    //导入客户信息表
    @RequestMapping(value = "/importExcelToClientInfo",method = RequestMethod.POST)
    public R importExcelToClientInfo(MultipartFile file) throws Exception {
        R r=new R();
        if (file==null){
            r.setCode(500);
            r.setMsg("上传文件为空，请选择文件");
            return r;
        }
        return clientListBaseInformationService.importExcelToClientInfo(file);
    }
    //根据客户id查询客户添加的所有国家
    @RequestMapping("/findCountryByClientId")
    public R findCountryByClientId(Long clientInfoId ){
        return clientListBaseInformationService.findCountryByClientId(clientInfoId);
    }
}
